/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.XMPPComponent;
/*     */ import com.zimbra.qa.unittest.prov.Names;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvXMPPComponent
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static Server server;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  44 */     provUtil = new LdapProvTestUtil();
/*  45 */     prov = provUtil.getProv();
/*  46 */     domain = provUtil.createDomain(baseDomainName());
/*  47 */     server = prov.getLocalServer();
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  52 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private XMPPComponent createXMPPComponent(String xmppCpntName) throws Exception {
/*  56 */     XMPPComponent xmppCpnt = prov.get(Key.XMPPComponentBy.name, xmppCpntName);
/*  57 */     Assert.assertNull(xmppCpnt);
/*     */     
/*  59 */     Map<String, Object> attrs = new HashMap();
/*  60 */     attrs.put("zimbraXMPPComponentCategory", "whatever");
/*  61 */     attrs.put("zimbraXMPPComponentClassName", "whatever");
/*  62 */     attrs.put("zimbraXMPPComponentType", "whatever");
/*  63 */     xmppCpnt = prov.createXMPPComponent(xmppCpntName, domain, server, attrs);
/*  64 */     Assert.assertNotNull(xmppCpnt);
/*     */     
/*  66 */     xmppCpnt = prov.get(Key.XMPPComponentBy.name, xmppCpntName);
/*  67 */     Assert.assertNotNull(xmppCpnt);
/*  68 */     Assert.assertEquals(xmppCpntName.toLowerCase(), xmppCpnt.getName().toLowerCase());
/*     */     
/*  70 */     return xmppCpnt;
/*     */   }
/*     */   
/*     */   private void deleteXMPPComponent(XMPPComponent xmppCpnt) throws Exception {
/*  74 */     String xmppCpntId = xmppCpnt.getId();
/*  75 */     prov.deleteXMPPComponent(xmppCpnt);
/*  76 */     xmppCpnt = prov.get(Key.XMPPComponentBy.id, xmppCpntId);
/*  77 */     Assert.assertNull(xmppCpnt);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createXMPPComponent() throws Exception {
/*  82 */     String XMPPCPNT_NAME = Names.makeXMPPName(genXMPPName());
/*  83 */     XMPPComponent xmppCpnt = createXMPPComponent(XMPPCPNT_NAME);
/*     */     
/*  85 */     deleteXMPPComponent(xmppCpnt);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createXMPPComponentAlreadyExists() throws Exception {
/*  90 */     String XMPPCPNT_NAME = Names.makeXMPPName(genXMPPName());
/*  91 */     XMPPComponent xmppCpnt = createXMPPComponent(XMPPCPNT_NAME);
/*     */     
/*  93 */     boolean caughtException = false;
/*     */     try {
/*  95 */       Map<String, Object> attrs = new HashMap();
/*  96 */       attrs.put("zimbraXMPPComponentCategory", "whatever");
/*  97 */       attrs.put("zimbraXMPPComponentClassName", "whatever");
/*  98 */       attrs.put("zimbraXMPPComponentType", "whatever");
/*  99 */       prov.createXMPPComponent(XMPPCPNT_NAME, domain, server, attrs);
/*     */     } catch (AccountServiceException e) {
/* 101 */       if ("account.IM_COMPONENT_EXISTS".equals(e.getCode())) {
/* 102 */         caughtException = true;
/*     */       }
/*     */     }
/* 105 */     Assert.assertTrue(caughtException);
/*     */     
/* 107 */     deleteXMPPComponent(xmppCpnt);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getXMPPComponent() throws Exception {
/* 112 */     String XMPPCPNT_NAME = Names.makeXMPPName(genXMPPName());
/* 113 */     XMPPComponent xmppCpnt = createXMPPComponent(XMPPCPNT_NAME);
/* 114 */     String xmppCpntId = xmppCpnt.getId();
/*     */     
/* 116 */     xmppCpnt = prov.get(Key.XMPPComponentBy.id, xmppCpntId);
/* 117 */     Assert.assertEquals(xmppCpntId, xmppCpnt.getId());
/*     */     
/* 119 */     xmppCpnt = prov.get(Key.XMPPComponentBy.name, XMPPCPNT_NAME);
/* 120 */     Assert.assertEquals(xmppCpntId, xmppCpnt.getId());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 126 */     deleteXMPPComponent(xmppCpnt);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getXMPPComponentNotExist() throws Exception {
/* 131 */     String XMPPCPNT_NAME = Names.makeXMPPName(genXMPPName());
/* 132 */     XMPPComponent xmppCpnt = prov.get(Key.XMPPComponentBy.name, XMPPCPNT_NAME);
/* 133 */     Assert.assertNull(xmppCpnt);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAllXMPPComponents() throws Exception {
/* 138 */     String XMPPCPNT_NAME_1 = Names.makeXMPPName(genXMPPName("1"));
/* 139 */     XMPPComponent xmppCpnt1 = createXMPPComponent(XMPPCPNT_NAME_1);
/*     */     
/* 141 */     String XMPPCPNT_NAME_2 = Names.makeXMPPName(genXMPPName("2"));
/* 142 */     XMPPComponent xmppCpnt2 = createXMPPComponent(XMPPCPNT_NAME_2);
/*     */     
/* 144 */     List<XMPPComponent> allXMPPCpnts = prov.getAllXMPPComponents();
/* 145 */     Assert.assertEquals(2L, allXMPPCpnts.size());
/*     */     
/* 147 */     Set<String> allXMPPCpntIds = new HashSet();
/* 148 */     for (XMPPComponent xmppCpnt : allXMPPCpnts) {
/* 149 */       allXMPPCpntIds.add(xmppCpnt.getId());
/*     */     }
/* 151 */     Assert.assertTrue(allXMPPCpntIds.contains(xmppCpnt1.getId()));
/* 152 */     Assert.assertTrue(allXMPPCpntIds.contains(xmppCpnt2.getId()));
/*     */     
/* 154 */     deleteXMPPComponent(xmppCpnt1);
/* 155 */     deleteXMPPComponent(xmppCpnt2);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvXMPPComponent.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */